package com.sengled.cloud.biz.union.mgt.dao.sys.provider;

import com.sengled.cloud.biz.union.mgt.model.po.RoleModulePermission;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by csolo on 2017/11/9.
 */
public class ShopAccountModuleDaoProvider {

    public String batchInsert(Map map) {
        List<Long> moduleIds = (List<Long>) map.get("moduleIds");
        Long shopAccountId = (Long)map.get("shopAccountId");
        StringBuilder sb = new StringBuilder();
        if (null != moduleIds && moduleIds.size() > 0) {
            sb.append("INSERT INTO shop_account_module(shop_account_id,module_id,create_date) VALUES");
            /*MessageFormat mf = new MessageFormat("(#'{'list[{0}].roleId},#'{'list[{0}].moduleId},#'{'list[{0}].permissionId},#'{'list[{0}].createDate})");
            for (RoleModulePermission roleModulePermission : roleModulePermissions) {
                    sb.append(mf.format(new Object[]{roleModulePermissions.indexOf(roleModulePermission)}));
                if (roleModulePermissions.indexOf(roleModulePermission) < roleModulePermissions.size() - 1) {
                    sb.append(",");
                }
            }*/
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            moduleIds.forEach(moduleId -> {
                 String cdate= sf.format(new Date());
                sb.append("("+shopAccountId+","+moduleId+",'"+cdate+"'),");
            });
        }
        sb.deleteCharAt(sb.length()-1);
        System.out.println("sql : ---------------->"+sb.toString());
        return sb.toString();
    }
}
